<template>
	<view class="content">
		<scroll-view class="nav" scroll-x :scroll-left="scrollLeft">
			<view class="nav_box">
				<block class="nav_block" v-for="(item, index) in navList" :key="index">
					<view class="nav_item" @tap="navClick(index,item.sid)" :class="{ nav_active: item.is_result }">{{ item.subject_name }}</view>
				</block>
			</view>
		</scroll-view>
		<view class="he"></view>
		<view class="list" v-for="(value,index) in datas" :key="index">
			<view class="item-left">
				<view class="item-left-top">{{value.section_name}}</view>
				<view class="item-left-bottom">上次练习至{{value.question_num}}题　{{value.creat_time}}</view>
			</view>
			<navigator hover-class="false" :url="'practice-breaking?interest_id='+value.interest_id" class="item-right">查看报告</navigator>
		</view>
		<uni-load-more v-if="datas.length>5" :status="status" :content-text="contentText" />
		<view class="tishi" v-if="datas.length==0">
			<view>暂无记录！</view>
		</view>
	</view>
</template>

<script>
	import cDate from '@/common/util.js';
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
	export default {
		components: {
			uniLoadMore
		},
		data() {
			return {
				scrollLeft: 0,
				navList: [],
				datas: [], // 遍历的数据项
				sid: '',
				page: 1,
				reload: true,
				status: 'more',
				contentText: {
					contentdown: '上拉加载更多',
					contentrefresh: '加载中',
					contentnomore: '没有更多',
					contentnot: "没数据"
				},
				student_id: ''
			}
		},
		onPullDownRefresh() {
			this.reload = true;
			this.page = 1;
			this.last_id = '';
			this.getlist();
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onReachBottom() {
			this.status = 'loading';
			this.page = this.page + 1;
			var _this = this;
			setTimeout(function() {
				_this.getlist();
			}, 500);
		},
		onLoad(e) {
			this.student_id = e.student_id;
			this.$zapi.apiPost('user/subject.Lists/subjectLists',{student_id:this.student_id}).then(res => {
				if (res.data.code == 200) {
					var data = res.data.data;
					var length = data.length;
					for (var i = 0; i < length; i++) {
						data[i]['subject_name'] = data[i]['subject_name'].replace(/\s+/g, "");
					}
					this.navList = data;
					this.sid = data[0].sid;
					this.navList[0].is_result = true;
					this.getlist();
				}
			});

		},
		methods: {
			navClick(index, sid) {
				/**
				 * 更新导航
				 */
				this.currentNav = index;
				for (let i = 0; i < this.navList.length; i++) {
					if (i == index) {
						this.navList[i].is_result = true;
					} else {
						this.navList[i].is_result = false;
					}
				}
				var len = this.navList.length;
				this.navList.splice(len);
				this.sid = sid;
				this.page = 1;
				this.reload = true;
				this.getlist();
			},
			getlist: function() {
				var data = {};
				if (this.sid != '') {
					data.subjectid = this.sid;
				}
				data.practice_state = 2;
				data.page = this.page;
				data.pagesize = 6;
				data.student_id = this.student_id;
				this.$zapi.apiPost('user/Interest.User/InterestList', data).then(res => {
					if (res.data.code == 200) {
						var list = res.data.data.data;
						for (let i = 0; i < list.length; i++) {
							list[i].creat_time = cDate.getBriefTime(list[i].creat_time);
						}
						this.datas = this.reload ? list : this.datas.concat(list);
						this.reload = false;
						this.status = 'more';
					} else {
						if (this.reload) {
							this.datas = [];
							// 	uni.showToast({
							// 	title: res.data.msg,
							// 	icon: 'none'
							// });
						} else {
							this.status = 'noMore';
						}
					}

				});
			}
		}
	}
</script>

<style>
	.tishi {
		width: 100%;
		margin-top: 300upx;
		display: flex;
		justify-content: center;
		align-items: center;
		flex-direction: column;
	}

	.tishi i {
		font-size: 380upx;
		color: rgba(0, 213, 162, 1);
		line-height: 180upx;
	}

	.list {
		padding: 0 4%;
		display: flex;
		justify-content: space-between;
		height: 184upx;
		align-items: center;
		width: 92%;
		margin-bottom: 10upx;
		background: #FFFFFF;
	}
	.item-left{
		width: 100%;
	}
	.item-left-top {
		font-size: 36upx;
		color: #333333;
		line-height: 60upx;
		max-width: 70%;
		overflow: hidden;
		text-overflow:ellipsis;
		white-space: nowrap;
	}

	.item-left-bottom {
		font-size: 28upx;
		color: #666666;
	}

	.item-right {
		position: absolute;
		right: 26upx;
		width: 180upx;
		height: 60upx;
		line-height: 60upx;
		font-size: 34upx;
		text-align: center;
		color: #FFFFFF;
		background: #FF9900;
	}

	.he {
		height: 90upx;
		background: #FFFFFF;
	}

	.nav {
		position: fixed;
		width: 100%;
		z-index: 1;
		color: #FFFFFF;
		background: #FF9900;
	}

	.nav_box {
		display: flex;
		white-space: nowrap;
	}

	.nav_item {
		display: flex;
		align-items: center;
		height: 100upx;
		line-height: 80upx;
		padding: 0 30upx;
		align-items: center;
		justify-content: center;
		flex-direction: column;
		font-size: 30upx;
	}

	.nav_active {
		font-weight: bold;
	}

	.nav_active:after {
		content: '';
		line-height: 100upx;
		background: #fff;
		height: 4upx;
		width: 28upx;
		font-weight: bold;
	}

	.nav_block {
		display: flex;
	}

	html {
		font-size: 26upx;
	}

	.content {
		min-height: 100%;
		width: 100%;
		/* overflow: auto; */
		position: absolute;
		padding-bottom: 110upx;
		background: #FAFAFA;
	}
</style>
